package org.visitor.visitorserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.visitor.visitorserver.dto.FormatResponse;
import org.visitor.visitorserver.mapper.AppointmentMapper;

import java.util.Map;

@RestController
@RequestMapping("/api/appointment")
public class AppointmentController {
    @Autowired
    private AppointmentMapper appointmentMapper;
    @Autowired
    private FormatResponse formatResponse;

    @PostMapping("/insert")
    public FormatResponse insertOneAppointment(@RequestBody Map<String, String> requestBody) {
        try {
            appointmentMapper.insertOneAppointment(requestBody);
            formatResponse.setSuccess(true);
            formatResponse.setCode(200);
            formatResponse.setMsg("ok");
        } catch (Exception e) {
            formatResponse.setSuccess(false);
            formatResponse.setCode(400);
            formatResponse.setMsg(e.getMessage());
        }
        return formatResponse;
    }
}
